<template>
	<div>
		<span>
			<font class="font" size="5" color="grey">药房退药信息</font>
		</span>
		<el-divider></el-divider>
		<el-form :inline="true" :model="formInline" class="demo-form-inline">
			<el-form-item label="就诊卡ID:" required="">
				<el-input v-model="formInline.idnumber" placeholder="请输入患者就诊卡ID"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="getpdrug()">搜索</el-button>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="getallpdrug()">显示所有开药记录</el-button>
			</el-form-item>
		</el-form>
		<el-divider></el-divider>
		<el-table :data="pdrug" style="width: 100%">
			<el-table-column prop="idnumber" label="就诊卡ID" width="120">
			</el-table-column>
			<el-table-column prop="name" label="患者姓名" width="120">
			</el-table-column>
			<el-table-column prop="drug" label="药品名称" width="150">
			</el-table-column>
			<el-table-column prop="format" label="药品规格" width="180">
			</el-table-column>
			<el-table-column prop="amount" label="数量" width="120">
			</el-table-column>
			<el-table-column prop="money" label="消费金额" width="120">
			</el-table-column>
			<el-table-column prop="state" label="发药状态" width="120">
			</el-table-column>
			<el-table-column label="操作" width="180">
				<template slot-scope="scope">
					<el-button type="primary" @click="deleteRow(scope.$index,pdrug)">退药</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
	import {
		showMsgTitle
	} from '@/utils/api'
	import {
		showMsgConfirm
	} from '@/utils/api'
	import {
		getRequest
	} from '@/utils/api'
	import {
		postRequest
	} from '@/utils/api'
	import {
		uploadFileRequest
	} from '@/utils/api'
	import {
		putRequest
	} from '@/utils/api'
	import {
		deleteRequest
	} from '@/utils/api'
	import {
		showConstants
	} from '@/utils/api'
	import {
		mapMutations
	} from "vuex";

	export default {
		data() {
			return {
				formInline: {
					idnumber: ''
				},
				pdrug: [],
			}
		},
		methods: {
			deleteRow(index, rows) {
				console.log(this.pdrug[index].num);
				postRequest('/delpdrug?num=' + this.pdrug[index].num);
				rows.splice(index, 1);
			},
			getallpdrug() {
				this.$axios.get('http://localhost:8081/alpdrug').then((result) => {
					console.log(result.data);
					this.pdrug = result.data
				}).catch((err) => {
					console.log(error);
				});
			},
			getpdrug() {
				//postRequest('/idregister?idnumber='+this.formInline.idnumber);
				this.$axios.get('http://localhost:8081/idpdrug?idnumber=' + this.formInline.idnumber).then((result) => {
					console.log(result.data);
					this.pdrug = result.data
				}).catch((err) => {
					console.log(error);
				});
			}
		}
	}
</script>

<style>
</style>
